package com.example.userservice.controller;

import com.example.userservice.common.PageParams;
import com.example.userservice.common.RestResponse;
import com.example.userservice.model.ListResponse;
import com.example.userservice.model.User;
import com.example.userservice.service.AgencyService;

import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-06-23
 **/
@RestController
@RequestMapping("/agency")
public class AgencyController {


    @Autowired
    private AgencyService agencyService;

    @RequestMapping("/agentList")
    public RestResponse<ListResponse<User>> agentList(Integer limit, Integer offset) {
        PageParams pageParams = new PageParams();
        pageParams.setLimit(limit);
        pageParams.setOffset(offset);
        Pair<List<User>,Long> pair = agencyService.getAllAgent(pageParams);
        ListResponse<User> response = ListResponse.build(pair.getKey(),pair.getValue());
        return RestResponse.success(response);
    }


    @RequestMapping("/agentDetail")
    public RestResponse<User> agentDetail(Long id) {
        User user = agencyService.getAgentDetail(id);
        return RestResponse.success(user);
    }
}








